package ysq.xyg.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.github.pagehelper.StringUtil;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;
import ysq.xyg.dao.MyInviteDao;
import ysq.xyg.model.MyInvite;
import ysq.xyg.service.MyInviteService;
import ysq.xyg.util.BaseUtil;

import javax.annotation.Resource;
import java.util.List;


/**
 * @author yu sheng qiang
 * @create 2017-03-22 15:36
 **/
@Service("myInviteService")
public class MyInviteServiceImpl extends BaseServiceImpl<MyInvite> implements MyInviteService {


    @Resource
    private MyInviteDao myInviteDao;
    @Autowired
    public void setMyInviteDao(MyInviteDao myInviteDao) {
        this.baseDao = myInviteDao;
    }
    @Override
    public PageInfo<MyInvite> pageInfoLeft(MyInvite myInvite, int pageSize, int pageNum) {
        PageHelper.startPage(pageNum, pageSize);
        if(StringUtil.isNotEmpty(myInvite.getNickName())){
            myInvite.setNickName(BaseUtil.encodeBase64String(myInvite.getNickName()));
        }
        if(StringUtil.isNotEmpty(myInvite.getMyNickName())){
            myInvite.setMyNickName(BaseUtil.encodeBase64String(myInvite.getMyNickName()));
        }
        List<MyInvite> list = myInviteDao.leftList(myInvite);
        return new PageInfo<MyInvite>(list);
    }
    @Override
    public List<MyInvite> listLeft(MyInvite myInvite) {
        if(StringUtil.isNotEmpty(myInvite.getNickName())){
            myInvite.setNickName(BaseUtil.encodeBase64String(myInvite.getNickName()));
        }
        if(StringUtil.isNotEmpty(myInvite.getMyNickName())){
            myInvite.setMyNickName(BaseUtil.encodeBase64String(myInvite.getMyNickName()));
        }
        List<MyInvite> list = myInviteDao.leftList(myInvite);
        return list;
    }
    @Override
    public PageInfo<MyInvite> pageInfo(MyInvite myInvite, int pageSize, int pageNum) {
        PageHelper.startPage(pageNum, pageSize);
        // 通用Example查询
        Example example = new Example(MyInvite.class);
        Example.Criteria criteria = example.createCriteria();
        if (StringUtils.isNotEmpty(myInvite.getInviteId())) {
            criteria.andLike("inviteId", myInvite.getInviteId());
        }
        if (StringUtils.isNotEmpty(myInvite.getMyId())) {
            criteria.andLike("myId", myInvite.getMyId());
        }
        List<MyInvite> list = myInviteDao.selectByExample(example);
        return new PageInfo<MyInvite>(list);
    }
    @Override
    public List<MyInvite> list(MyInvite myInvite) {
        // 通用Example查询
        Example example = new Example(MyInvite.class);
        Example.Criteria criteria = example.createCriteria();
        if (StringUtils.isNotEmpty(myInvite.getInviteId())) {
            criteria.andLike("inviteId", myInvite.getInviteId());
        }
        if (StringUtils.isNotEmpty(myInvite.getMyId())) {
            criteria.andLike("myId", myInvite.getMyId());
        }
        example.setOrderByClause(" create_time desc ");
        List<MyInvite> list = myInviteDao.selectByExample(example);
        return list;
    }
}
